<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Models\Category;
use App\Models\Brand;
use View;
use App\Services\CartService;

class ViewServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('dashboard.includes.category_select', function($view) {
            $categories = Category::orderBy('sort')->get();
            $view->with('categories', $categories);
        });

        View::composer('dashboard.includes.topcategory_select', function($view) {
            $categories = Category::top()->get();
            $view->with('categories', $categories);
        });

        View::composer(['dashboard.includes.brand_select','dashboard.components.brand_select'], function($view) {
            $brands = Brand::orderBy('id')->get();
            $view->with('brands', $brands);
        });

        View::composer('home.components.cart-logo', function($view) {
            $config = \App\Models\Config::first();
            $view->with('cfg', $config);
            $service = new CartService;
            $carts = $service->getCarts();
            $view->with('carts', $carts);
        });

        View::composer(['home.components.main-nav', 'home.components.category-left'], function($view) {
            $categories = \App\Models\Category::top()->with('subcates')->get();
            $view->with('menus', $categories);
        });

        View::composer('dashboard.bottomnav.create', function($view) {
            $view->with('topnavs', \App\Models\Bottomnav::topnav()->get());
        });

        View::composer(
            'home.order.create', 'App\Http\Views\Composers\OrderinfoComposer'
        );

        //View::composer();
    }
}
